const userService = require("../../services/userService");

var app = getApp();
Page({
  data: {
    assets: app.assets,
    assetsByEnv: app.assetsByEnv,
    id: "",
    detail: {},
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "详情",
    });

    this.setData({
      id: options.id,
    });

    this._getArticleDetail();
  },

  _getArticleDetail: function () {
    userService.getArticleDetail({ id: this.data.id }).then(
      (data) => {
        if (data.result) {
          data.obj.content = data.obj.content.replace(
            /\<img/gi,
            '<img style="max-width:100%;height:auto" '
          );
          this.setData({
            detail: data.obj,
          });
        } else {
          wx.showToast({ title: data.errorMsg, icon: "none" });
        }
      },
      (error) => {
        console.log(error);
        wx.showToast({ title: "getArticleDetail接口异常", icon: "none" });
      }
    );
  },
});
